/**
 * Created with IntelliJ IDEA.
 * Description:判断是不是二叉搜索树
 * User: wangxin
 * Date: 2024-11-08
 * Time: 17:47
 */

import java.util.*;


   class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;
    public TreeNode(int val) {
      this.val = val;
    }
  }

public class test1 {
    private int pre = Integer.MIN_VALUE;
    public boolean isValidBST (TreeNode root) {
        // write code here
        if(root == null){
            return true;
        }
        if(!isValidBST(root.left)){
            return false;
        }
        if(root.val < pre){
            return false;
        }
        pre = root.val;

        return isValidBST(root.right);
    }
}
